<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Net::HTTPResponse - net/http: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-Net::HTTPResponse-label-About+the+Examples">About the Examples</a>
    <li><a href="#class-Net::HTTPResponse-label-Returned+Responses">Returned Responses</a>
    <li><a href="#class-Net::HTTPResponse-label-Response+Subclasses">Response Subclasses</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="HTTPHeader.html">Net::HTTPHeader</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-body_permitted-3F">::body_permitted?</a>
    <li ><a href="#method-c-each_response_header">::each_response_header</a>
    <li ><a href="#method-c-read_status_line">::read_status_line</a>
    <li ><a href="#method-c-response_class">::response_class</a>
    <li ><a href="#method-i-body">#body</a>
    <li ><a href="#method-i-body-3D">#body=</a>
    <li ><a href="#method-i-body_encoding-3D">#body_encoding=</a>
    <li ><a href="#method-i-entity">#entity</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-read_body">#read_body</a>
    <li ><a href="#method-i-value">#value</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Net::HTTPResponse">
    <h1 id="class-Net::HTTPResponse" class="class">
      class Net::HTTPResponse
    </h1>

    <section class="description">
    
<p>This class is the base class for Net::HTTP response classes.</p>

<h2 id="class-Net::HTTPResponse-label-About+the+Examples">About the Examples<span><a href="#class-Net::HTTPResponse-label-About+the+Examples">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h2 id="class-Net::HTTPResponse-label-Returned+Responses">Returned Responses<span><a href="#class-Net::HTTPResponse-label-Returned+Responses">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Method <a href="HTTP.html#method-c-get_response"><code>Net::HTTP.get_response</code></a> returns an instance of one of the subclasses of Net::HTTPResponse:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">uri</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-string">&#39;/nosuch&#39;</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTPNotFound 404 Not Found readbody=true&gt;</span>
</pre>

<p>As does method <a href="HTTP.html#method-i-request"><code>Net::HTTP#request</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>)
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
<span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

<p>Class Net::HTTPResponse includes module <a href="HTTPHeader.html"><code>Net::HTTPHeader</code></a>, which provides access to response header values via (among others):</p>
<ul><li>
<p>Hash-like method <code>[]</code>.</p>
</li><li>
<p>Specific reader methods, such as <code>content_type</code>.</p>
</li></ul>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">res</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">uri</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
<span class="ruby-identifier">res</span>[<span class="ruby-string">&#39;Content-Type&#39;</span>]               <span class="ruby-comment"># =&gt; &quot;text/html; charset=UTF-8&quot;</span>
<span class="ruby-identifier">res</span>.<span class="ruby-identifier">content_type</span>                  <span class="ruby-comment"># =&gt; &quot;text/html&quot;</span>
</pre>

<h2 id="class-Net::HTTPResponse-label-Response+Subclasses">Response Subclasses<span><a href="#class-Net::HTTPResponse-label-Response+Subclasses">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Class Net::HTTPResponse has a subclass for each <a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes">HTTP status code</a>. You can look up the response class for a given code:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPResponse</span><span class="ruby-operator">::</span><span class="ruby-constant">CODE_TO_OBJ</span>[<span class="ruby-string">&#39;200&#39;</span>] <span class="ruby-comment"># =&gt; Net::HTTPOK</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPResponse</span><span class="ruby-operator">::</span><span class="ruby-constant">CODE_TO_OBJ</span>[<span class="ruby-string">&#39;400&#39;</span>] <span class="ruby-comment"># =&gt; Net::HTTPBadRequest</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPResponse</span><span class="ruby-operator">::</span><span class="ruby-constant">CODE_TO_OBJ</span>[<span class="ruby-string">&#39;404&#39;</span>] <span class="ruby-comment"># =&gt; Net::HTTPNotFound</span>
</pre>

<p>And you can retrieve the status code for a response object:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">uri</span>).<span class="ruby-identifier">code</span>                 <span class="ruby-comment"># =&gt; &quot;200&quot;</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-string">&#39;/nosuch&#39;</span>).<span class="ruby-identifier">code</span> <span class="ruby-comment"># =&gt; &quot;404&quot;</span>
</pre>

<p>The response subclasses (indentation shows class hierarchy):</p>
<ul><li>
<p><a href="HTTPUnknownResponse.html"><code>Net::HTTPUnknownResponse</code></a> (for unhandled HTTP extensions).</p>
</li><li>
<p><a href="HTTPInformation.html"><code>Net::HTTPInformation</code></a>:</p>
<ul><li>
<p><a href="HTTPContinue.html"><code>Net::HTTPContinue</code></a> (100)</p>
</li><li>
<p><a href="HTTPSwitchProtocol.html"><code>Net::HTTPSwitchProtocol</code></a> (101)</p>
</li><li>
<p><a href="HTTPProcessing.html"><code>Net::HTTPProcessing</code></a> (102)</p>
</li><li>
<p><a href="HTTPEarlyHints.html"><code>Net::HTTPEarlyHints</code></a> (103)</p>
</li></ul>
</li><li>
<p><a href="HTTPSuccess.html"><code>Net::HTTPSuccess</code></a>:</p>
<ul><li>
<p><a href="HTTPOK.html"><code>Net::HTTPOK</code></a> (200)</p>
</li><li>
<p><a href="HTTPCreated.html"><code>Net::HTTPCreated</code></a> (201)</p>
</li><li>
<p><a href="HTTPAccepted.html"><code>Net::HTTPAccepted</code></a> (202)</p>
</li><li>
<p><a href="HTTPNonAuthoritativeInformation.html"><code>Net::HTTPNonAuthoritativeInformation</code></a> (203)</p>
</li><li>
<p><a href="HTTPNoContent.html"><code>Net::HTTPNoContent</code></a> (204)</p>
</li><li>
<p><a href="HTTPResetContent.html"><code>Net::HTTPResetContent</code></a> (205)</p>
</li><li>
<p><a href="HTTPPartialContent.html"><code>Net::HTTPPartialContent</code></a> (206)</p>
</li><li>
<p><a href="HTTPMultiStatus.html"><code>Net::HTTPMultiStatus</code></a> (207)</p>
</li><li>
<p><a href="HTTPAlreadyReported.html"><code>Net::HTTPAlreadyReported</code></a> (208)</p>
</li><li>
<p><a href="HTTPIMUsed.html"><code>Net::HTTPIMUsed</code></a> (226)</p>
</li></ul>
</li><li>
<p><a href="HTTPRedirection.html"><code>Net::HTTPRedirection</code></a>:</p>
<ul><li>
<p><a href="HTTPMultipleChoices.html"><code>Net::HTTPMultipleChoices</code></a> (300)</p>
</li><li>
<p><a href="HTTPMovedPermanently.html"><code>Net::HTTPMovedPermanently</code></a> (301)</p>
</li><li>
<p><a href="HTTPFound.html"><code>Net::HTTPFound</code></a> (302)</p>
</li><li>
<p><a href="HTTPSeeOther.html"><code>Net::HTTPSeeOther</code></a> (303)</p>
</li><li>
<p><a href="HTTPNotModified.html"><code>Net::HTTPNotModified</code></a> (304)</p>
</li><li>
<p><a href="HTTPUseProxy.html"><code>Net::HTTPUseProxy</code></a> (305)</p>
</li><li>
<p><a href="HTTPTemporaryRedirect.html"><code>Net::HTTPTemporaryRedirect</code></a> (307)</p>
</li><li>
<p><a href="HTTPPermanentRedirect.html"><code>Net::HTTPPermanentRedirect</code></a> (308)</p>
</li></ul>
</li><li>
<p><a href="HTTPClientError.html"><code>Net::HTTPClientError</code></a>:</p>
<ul><li>
<p><a href="HTTPBadRequest.html"><code>Net::HTTPBadRequest</code></a> (400)</p>
</li><li>
<p><a href="HTTPUnauthorized.html"><code>Net::HTTPUnauthorized</code></a> (401)</p>
</li><li>
<p><a href="HTTPPaymentRequired.html"><code>Net::HTTPPaymentRequired</code></a> (402)</p>
</li><li>
<p><a href="HTTPForbidden.html"><code>Net::HTTPForbidden</code></a> (403)</p>
</li><li>
<p><a href="HTTPNotFound.html"><code>Net::HTTPNotFound</code></a> (404)</p>
</li><li>
<p><a href="HTTPMethodNotAllowed.html"><code>Net::HTTPMethodNotAllowed</code></a> (405)</p>
</li><li>
<p><a href="HTTPNotAcceptable.html"><code>Net::HTTPNotAcceptable</code></a> (406)</p>
</li><li>
<p><a href="HTTPProxyAuthenticationRequired.html"><code>Net::HTTPProxyAuthenticationRequired</code></a> (407)</p>
</li><li>
<p><a href="HTTPRequestTimeout.html"><code>Net::HTTPRequestTimeOut</code></a> (408)</p>
</li><li>
<p><a href="HTTPConflict.html"><code>Net::HTTPConflict</code></a> (409)</p>
</li><li>
<p><a href="HTTPGone.html"><code>Net::HTTPGone</code></a> (410)</p>
</li><li>
<p><a href="HTTPLengthRequired.html"><code>Net::HTTPLengthRequired</code></a> (411)</p>
</li><li>
<p><a href="HTTPPreconditionFailed.html"><code>Net::HTTPPreconditionFailed</code></a> (412)</p>
</li><li>
<p><a href="HTTPPayloadTooLarge.html"><code>Net::HTTPRequestEntityTooLarge</code></a> (413)</p>
</li><li>
<p><a href="HTTPURITooLong.html"><code>Net::HTTPRequestURITooLong</code></a> (414)</p>
</li><li>
<p><a href="HTTPUnsupportedMediaType.html"><code>Net::HTTPUnsupportedMediaType</code></a> (415)</p>
</li><li>
<p><a href="HTTPRangeNotSatisfiable.html"><code>Net::HTTPRequestedRangeNotSatisfiable</code></a> (416)</p>
</li><li>
<p><a href="HTTPExpectationFailed.html"><code>Net::HTTPExpectationFailed</code></a> (417)</p>
</li><li>
<p><a href="HTTPMisdirectedRequest.html"><code>Net::HTTPMisdirectedRequest</code></a> (421)</p>
</li><li>
<p><a href="HTTPUnprocessableEntity.html"><code>Net::HTTPUnprocessableEntity</code></a> (422)</p>
</li><li>
<p><a href="HTTPLocked.html"><code>Net::HTTPLocked</code></a> (423)</p>
</li><li>
<p><a href="HTTPFailedDependency.html"><code>Net::HTTPFailedDependency</code></a> (424)</p>
</li><li>
<p><a href="HTTPUpgradeRequired.html"><code>Net::HTTPUpgradeRequired</code></a> (426)</p>
</li><li>
<p><a href="HTTPPreconditionRequired.html"><code>Net::HTTPPreconditionRequired</code></a> (428)</p>
</li><li>
<p><a href="HTTPTooManyRequests.html"><code>Net::HTTPTooManyRequests</code></a> (429)</p>
</li><li>
<p><a href="HTTPRequestHeaderFieldsTooLarge.html"><code>Net::HTTPRequestHeaderFieldsTooLarge</code></a> (431)</p>
</li><li>
<p><a href="HTTPUnavailableForLegalReasons.html"><code>Net::HTTPUnavailableForLegalReasons</code></a> (451)</p>
</li></ul>
</li><li>
<p><a href="HTTPServerError.html"><code>Net::HTTPServerError</code></a>:</p>
<ul><li>
<p><a href="HTTPInternalServerError.html"><code>Net::HTTPInternalServerError</code></a> (500)</p>
</li><li>
<p><a href="HTTPNotImplemented.html"><code>Net::HTTPNotImplemented</code></a> (501)</p>
</li><li>
<p><a href="HTTPBadGateway.html"><code>Net::HTTPBadGateway</code></a> (502)</p>
</li><li>
<p><a href="HTTPServiceUnavailable.html"><code>Net::HTTPServiceUnavailable</code></a> (503)</p>
</li><li>
<p><a href="HTTPGatewayTimeout.html"><code>Net::HTTPGatewayTimeOut</code></a> (504)</p>
</li><li>
<p><a href="HTTPVersionNotSupported.html"><code>Net::HTTPVersionNotSupported</code></a> (505)</p>
</li><li>
<p><a href="HTTPVariantAlsoNegotiates.html"><code>Net::HTTPVariantAlsoNegotiates</code></a> (506)</p>
</li><li>
<p><a href="HTTPInsufficientStorage.html"><code>Net::HTTPInsufficientStorage</code></a> (507)</p>
</li><li>
<p><a href="HTTPLoopDetected.html"><code>Net::HTTPLoopDetected</code></a> (508)</p>
</li><li>
<p><a href="HTTPNotExtended.html"><code>Net::HTTPNotExtended</code></a> (510)</p>
</li><li>
<p><a href="HTTPNetworkAuthenticationRequired.html"><code>Net::HTTPNetworkAuthenticationRequired</code></a> (511)</p>
</li></ul>
</li></ul>

<p>There is also the Net::HTTPBadResponse exception which is raised when there is a protocol error.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="CODE_CLASS_TO_OBJ">CODE_CLASS_TO_OBJ
          <dd>
          <dt id="CODE_TO_OBJ">CODE_TO_OBJ
          <dd>
        </dl>
        </section>

        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-body_encoding" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">body_encoding</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the value set by <a href="HTTPResponse.html#attribute-i-body_encoding"><code>body_encoding</code></a>=, or <code>false</code> if none; see <a href="HTTPResponse.html#method-i-body_encoding-3D"><code>body_encoding=</code></a>.</p>
              </div>
            </div>
          <div id="attribute-i-code" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">code</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>The HTTP result code string. For example, ‘302’.  You can also determine the response type by examining which response subclass the response object is an instance of.</p>
              </div>
            </div>
          <div id="attribute-i-decode_content" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">decode_content</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Set to true automatically when the request did not contain an Accept-Encoding header from the user.</p>
              </div>
            </div>
          <div id="attribute-i-http_version" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">http_version</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>The HTTP version supported by the server.</p>
              </div>
            </div>
          <div id="attribute-i-ignore_eof" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">ignore_eof</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Whether to ignore EOF when reading bodies with a specified Content-Length header.</p>
              </div>
            </div>
          <div id="attribute-i-message" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">message</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>The HTTP result message sent by the server. For example, ‘Not Found’.</p>
              </div>
            </div>
          <div id="attribute-i-msg" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">msg</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>The HTTP result message sent by the server. For example, ‘Not Found’.</p>
              </div>
            </div>
          <div id="attribute-i-uri" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">uri</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>The URI used to fetch this response.  The response URI is only available if a URI was used to create the request.</p>
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-body_permitted-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">body_permitted?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>true if the response has a body.</p>

                              <div class="method-source-code" id="body_permitted-3F-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 138</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">body_permitted?</span>
  <span class="ruby-keyword">self</span><span class="ruby-operator">::</span><span class="ruby-constant">HAS_BODY</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Class Methods</h3>
                </header>

                  <div id="method-c-each_response_header" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each_response_header</span><span
                                class="method-args">(sock) { |key, value| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="each_response_header-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 170</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_response_header</span>(<span class="ruby-identifier">sock</span>)
  <span class="ruby-identifier">key</span> = <span class="ruby-identifier">value</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">while</span> <span class="ruby-keyword">true</span>
    <span class="ruby-identifier">line</span> = <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">readuntil</span>(<span class="ruby-string">&quot;\n&quot;</span>, <span class="ruby-keyword">true</span>).<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\s+\z/</span>, <span class="ruby-string">&#39;&#39;</span>)
    <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">line</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?\s</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">line</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?\t</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">value</span>
      <span class="ruby-identifier">value</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&#39; &#39;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">empty?</span>
      <span class="ruby-identifier">value</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">strip</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">key</span>
      <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span> = <span class="ruby-identifier">line</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">/\s*:\s*/</span>, <span class="ruby-value">2</span>)
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPBadResponse</span>, <span class="ruby-string">&#39;wrong header line format&#39;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">yield</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">key</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-read_status_line" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">read_status_line</span><span
                                class="method-args">(sock)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="read_status_line-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 157</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">read_status_line</span>(<span class="ruby-identifier">sock</span>)
  <span class="ruby-identifier">str</span> = <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">readline</span>
  <span class="ruby-identifier">m</span> = <span class="ruby-regexp">/\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">str</span>) <span class="ruby-keyword">or</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPBadResponse</span>, <span class="ruby-node">&quot;wrong status line: #{str.dump}&quot;</span>
  <span class="ruby-identifier">m</span>.<span class="ruby-identifier">captures</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-response_class" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">response_class</span><span
                                class="method-args">(code)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="response_class-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 164</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">response_class</span>(<span class="ruby-identifier">code</span>)
  <span class="ruby-constant">CODE_TO_OBJ</span>[<span class="ruby-identifier">code</span>] <span class="ruby-keyword">or</span>
  <span class="ruby-constant">CODE_CLASS_TO_OBJ</span>[<span class="ruby-identifier">code</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>]] <span class="ruby-keyword">or</span>
  <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPUnknownResponse</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-body" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">body</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the string response body; note that repeated calls for the unmodified body return a cached string:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;/todos/1&#39;</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">head</span>(<span class="ruby-identifier">path</span>).<span class="ruby-identifier">body</span> <span class="ruby-comment"># No body.</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;{\n  \&quot;userId\&quot;: 1,\n  \&quot;id\&quot;: 1,\n  \&quot;title\&quot;: \&quot;delectus aut autem\&quot;,\n  \&quot;completed\&quot;: false\n}&quot;</span>
<span class="ruby-keyword">nil</span>
</pre>

                              <div class="method-source-code" id="body-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 399</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">body</span>
  <span class="ruby-identifier">read_body</span>()
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTPResponse.html#method-i-entity">entity</a>
                            </div>

                          </div>

                  <div id="method-i-body-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">body=</span><span
                                class="method-args">(value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the body of the response to the given value.</p>

                              <div class="method-source-code" id="body-3D-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 404</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">body=</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-ivar">@body</span> = <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-body_encoding-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">body_encoding=</span><span
                                class="method-args">(value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the encoding that should be used when reading the body:</p>
<ul><li>
<p>If the given value is an Encoding object, that encoding will be used.</p>
</li><li>
<p>Otherwise if the value is a string, the value of Encoding#find(value) will be used.</p>
</li><li>
<p>Otherwise an encoding will be deduced from the body itself.</p>
</li></ul>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;/&#39;</span>)

<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">encoding</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:ASCII-8BIT&gt;</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body_encoding</span> = <span class="ruby-string">&quot;UTF-8&quot;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">encoding</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:UTF-8&gt;</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="body_encoding-3D-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 253</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">body_encoding=</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">value</span> = <span class="ruby-constant">Encoding</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">value</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
  <span class="ruby-ivar">@body_encoding</span> = <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-entity" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">entity</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTPResponse.html#method-i-body">body</a>
                            </div>
                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="inspect-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 262</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inspect</span>
  <span class="ruby-node">&quot;#&lt;#{self.class} #{@code} #{@message} readbody=#{@read}&gt;&quot;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-read_body" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">read_body</span><span
                                class="method-args">(dest = nil, &amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Gets the entity body returned by the remote HTTP server.</p>

<p>If a block is given, the body is passed to the block, and the body is provided in fragments, as it is read in from the socket.</p>

<p>If <code>dest</code> argument is given, response is read into that variable, with <code>dest#&lt;&lt;</code> method (it could be String or IO, or any other object responding to <code>&lt;&lt;</code>).</p>

<p>Calling this method a second or subsequent time for the same <a href="HTTPResponse.html"><code>HTTPResponse</code></a> object will return the value already read.</p>

<pre class="ruby"><span class="ruby-identifier">http</span>.<span class="ruby-identifier">request_get</span>(<span class="ruby-string">&#39;/index.html&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">read_body</span>
}

<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request_get</span>(<span class="ruby-string">&#39;/index.html&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">read_body</span>.<span class="ruby-identifier">object_id</span>   <span class="ruby-comment"># 538149362</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">read_body</span>.<span class="ruby-identifier">object_id</span>   <span class="ruby-comment"># 538149362</span>
}

<span class="ruby-comment"># using iterator</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request_get</span>(<span class="ruby-string">&#39;/index.html&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">res</span>.<span class="ruby-identifier">read_body</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">segment</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">print</span> <span class="ruby-identifier">segment</span>
  <span class="ruby-keyword">end</span>
}
</pre>

                              <div class="method-source-code" id="read_body-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 355</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">read_body</span>(<span class="ruby-identifier">dest</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@read</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">IOError</span>, <span class="ruby-node">&quot;#{self.class}\#read_body called twice&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">dest</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">block</span>
    <span class="ruby-keyword">return</span> <span class="ruby-ivar">@body</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">to</span> = <span class="ruby-identifier">procdest</span>(<span class="ruby-identifier">dest</span>, <span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">stream_check</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@body_exist</span>
    <span class="ruby-identifier">read_body_0</span> <span class="ruby-identifier">to</span>
    <span class="ruby-ivar">@body</span> = <span class="ruby-identifier">to</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@body</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@read</span> = <span class="ruby-keyword">true</span>

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">enc</span> = <span class="ruby-ivar">@body_encoding</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Encoding</span>, <span class="ruby-keyword">false</span>, <span class="ruby-keyword">nil</span>
    <span class="ruby-comment"># Encoding: force given encoding</span>
    <span class="ruby-comment"># false/nil: do not force encoding</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-comment"># other value: detect encoding from body</span>
    <span class="ruby-identifier">enc</span> = <span class="ruby-identifier">detect_encoding</span>(<span class="ruby-ivar">@body</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-ivar">@body</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-identifier">enc</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">enc</span>

  <span class="ruby-ivar">@body</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-value" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">value</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Raises an HTTP error if the response is not 2xx (success).</p>

                              <div class="method-source-code" id="value-source">
            <pre><span class="ruby-comment"># File net/http/response.rb, line 285</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">value</span>
  <span class="ruby-identifier">error!</span> <span class="ruby-keyword">unless</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPSuccess</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

